<%@ page language="java" import="weaver.conn.RecordSet" pageEncoding="UTF-8" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.hrm.HrmUserVarify" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.conn.RecordSetDataSource" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import="java.util.*" %>
<%@ page import="weaver.formmode.setup.ModeRightInfo" %>
<script>
</script>
<%
    User user = HrmUserVarify.getUser(request, response);
    int userid = user.getUID();
    int formmodeid= 132;
    RecordSet rs = new RecordSet();
    RecordSetDataSource dataSource = new RecordSetDataSource( "xfcs" );
    RecordSetDataSource dataSource1 = new RecordSetDataSource( "xfcs" );
    out.print( ">>>>>>>>开始执行>>>>>>"+"<br/>");
    try {
        dataSource.executeSql("select * from SVG_RS_RYGL");
        int count = 0;
        int counts = dataSource.getCounts();
        out.print( ">>>>>>>>查询记录总数为："+counts+"<br/>");
        while (dataSource.next()){
            Map dataMap = new HashMap(  );
            String RowGuid = Util.null2String(dataSource.getString("RowGuid"));//工号
            dataMap.put("gh",Util.null2String(dataSource.getString("s_gongh")));//工号
            dataMap.put("gwkh",Util.null2String(dataSource.getString("s_gongwkh")));//公务卡号
            dataMap.put("szbmmc",Util.null2String(dataSource.getString("s_BuMenMC")));//所在部门名称
            dataMap.put("xm",Util.null2String(dataSource.getString("s_xingming")));//姓名
            dataMap.put("sfzhm",Util.null2String(dataSource.getString("s_shenfenzh")));//身份证号码
            String d_chushengny = Util.null2String(dataSource.getString("d_chushengny"));
            dataMap.put("csny","".equals(d_chushengny)?"":d_chushengny.substring( 0,10 ));//出生年月
            dataMap.put("mz",Util.null2String(dataSource.getString("s_minzu")));//民族
            dataMap.put("jg",Util.null2String(dataSource.getString("s_jiguan")));//籍贯
            dataMap.put("zzmm",Util.null2String(dataSource.getString("s_zhengzhimm")));//政治面貌
            dataMap.put("xl",Util.null2String(dataSource.getString("s_xueli")));//学历
            dataMap.put("hyzk",Util.null2String(dataSource.getString("s_HunYinZK")));//婚姻状况
            dataMap.put("zp",Util.null2String(dataSource.getString("pic_zhaop")));//照片
            dataMap.put("byxx",Util.null2String(dataSource.getString("s_BiYeXX")));//毕业学校
            dataMap.put("sxzy",Util.null2String(dataSource.getString("s_ZhuanYe")));//所学专业
            dataMap.put("wyyz",Util.null2String(dataSource.getString("s_WaiYuYZ")));//外语语种
            dataMap.put("wysp",Util.null2String(dataSource.getString("s_WaiYuSP")));//外语水平
            dataMap.put("csxl",Util.null2String(dataSource.getString("s_chushiXL")));//初始学历
            dataMap.put("jjxl",Util.null2String(dataSource.getString("s_jijiaoXL")));//继教学历
            dataMap.put("zd",Util.null2String(dataSource.getString("s_zaidian")));//宅电
            dataMap.put("tc",Util.null2String(dataSource.getString("s_TeChang")));//特长
            dataMap.put("yzbm",Util.null2String(dataSource.getString("s_YouZhengBM")));//邮政编码
            dataMap.put("hkszd",Util.null2String(dataSource.getString("s_HuKouZZ")));//户口所在地
            dataMap.put("lxdh",Util.null2String(dataSource.getString("s_lianxidh")));//联系电话
            dataMap.put("txdz",Util.null2String(dataSource.getString("s_TongXunDZ")));//通讯地址
            String d_canjiagzsj = Util.null2String(dataSource.getString("d_canjiagzsj"));
            dataMap.put("cjgzsj","".equals(d_canjiagzsj)?"":d_canjiagzsj.substring( 0,10 ));//参加工作时间
            dataMap.put("gl",Util.null2String(dataSource.getString("s_GongLing")));//工龄
            String d_RuBenDWRQ = Util.null2String(dataSource.getString("d_RuBenDWRQ"));
            dataMap.put("rbdwrq","".equals(d_RuBenDWRQ)?"":d_RuBenDWRQ.substring( 0,10 ));//入本单位日期
            String d_LiZhiRQ = Util.null2String(dataSource.getString("d_LiZhiRQ"));
            dataMap.put("lzrq","".equals(d_LiZhiRQ)?"":d_LiZhiRQ.substring( 0,10 ));//离职日期
            String d_LiTuiXiuRQ = Util.null2String(dataSource.getString("d_LiTuiXiuRQ"));
            dataMap.put("ltxrq","".equals(d_LiTuiXiuRQ)?"":d_LiTuiXiuRQ.substring( 0,10 ));//离退休日期
            dataMap.put("ygzlzqk",Util.null2String(dataSource.getString("s_YuanGongQK")));//员工在/离职情况
            dataMap.put("bdwgl",Util.null2String(dataSource.getString("s_BenDanWeiGL")));//本单位工龄
            dataMap.put("gwmc",Util.null2String(dataSource.getString("s_GangWeiMC")));//岗位名称
            dataMap.put("xrzw",Util.null2String(dataSource.getString("s_xianrenzw")));//现任职务
            dataMap.put("zczg",Util.null2String(dataSource.getString("s_zhicheng")));//职称（资格）
            dataMap.put("xzjb",Util.null2String(dataSource.getString("s_XingZhengJB")));//行政级别
            dataMap.put("ryzx",Util.null2String(dataSource.getString("s_RenYuanSX")));//人员属性
            dataMap.put("bz",Util.null2String(dataSource.getString("s_BeiZhu")));//备注
            int dataId = insertModelData(formmodeid,userid,dataMap);
            out.print( ">>>>>>>>RowGuid："+RowGuid+"<br/>");
            if(dataId>0){
                count++;
                out.print( ">>>>>>>>dataId："+dataId+">>>>>>>>>>>>"+count+"<br/>");
                dataSource1.executeSql("select s_xingming,s_xingbie,s_GuanXi,s_LianXiDH,s_gongzuodw from svg_rs_jiatcy where s_WaiJian='"+RowGuid+"'");
                while (dataSource1.next()){
                    String s_xingming = Util.null2String(dataSource1.getString("s_xingming"));
                    String s_xingbie = Util.null2String(dataSource1.getString("s_xingbie"));
                    String s_GuanXi = Util.null2String(dataSource1.getString("s_GuanXi"));
                    String s_LianXiDH = Util.null2String(dataSource1.getString("s_LianXiDH"));
                    String s_gongzuodw = Util.null2String(dataSource1.getString("s_gongzuodw"));
                    Object[] params = new Object[]{dataId,s_xingming,s_xingbie,s_GuanXi,s_LianXiDH,s_gongzuodw};
                    String sql = "insert into uf_rsgl_dt1 (mainid,xm,xb,ybrgx,lxdh,gzdw)values(?,?,?,?,?,?)";
                    if(rs.executeUpdate(sql,params)){
                        out.print( ">>>>>>>>明细1："+sql+"<br/>");
                    }
                }
                dataSource1.executeSql("select d_datefrom,d_dateto,s_gongzuodw,s_bumen,s_zhiwu from SVG_RS_GongZJL where s_waijian='"+RowGuid+"'");
                while (dataSource1.next()){
                    String d_datefrom = Util.null2String(dataSource1.getString("d_datefrom"));
                    String d_dateto = Util.null2String(dataSource1.getString("d_dateto"));
                    String s_gongzuodw = Util.null2String(dataSource1.getString("s_gongzuodw"));
                    String s_bumen = Util.null2String(dataSource1.getString("s_bumen"));
                    String s_zhiwu = Util.null2String(dataSource1.getString("s_zhiwu"));
                    Object[] params = new Object[]{dataId,d_datefrom,d_dateto,s_gongzuodw,s_bumen,s_zhiwu};
                    String sql = "insert into uf_rsgl_dt2 (mainid,ksrq,jsrq,gzdw,bm,zw)values(?,?,?,?,?,?)";
                    if(rs.executeUpdate(sql,params)){
                        out.print( ">>>>>>>>明细2："+sql+"<br/>");
                    }
                }
                dataSource1.executeSql("select  X_startdate,X_enddate,x_xuexiao,x_xuewei,x_zhengming from Xuexi where userguid='"+RowGuid+"'");
                while (dataSource1.next()){
                    String X_startdate = Util.null2String(dataSource1.getString("X_startdate"));
                    String X_enddate = Util.null2String(dataSource1.getString("X_enddate"));
                    String x_xuexiao = Util.null2String(dataSource1.getString("x_xuexiao"));
                    String x_xuewei = Util.null2String(dataSource1.getString("x_xuewei"));
                    String x_zhengming = Util.null2String(dataSource1.getString("x_zhengming"));
                    Object[] params = new Object[]{dataId,X_startdate,X_enddate,x_xuexiao,x_xuewei,x_zhengming};
                    String sql = "insert into uf_rsgl_dt3 (mainid,kssj,jssj,xxmc,hdxw,zmr)values(?,?,?,?,?,?)";
                    if(rs.executeUpdate(sql,params)){
                        out.print( ">>>>>>>>明细3："+sql+"<br/>");
                    }
                }
            }
        }
        out.print( "执行成功主表数据记录数：>>>"+count+",主表数据总记录数：>>>"+counts);
    }catch (Exception e){
        out.print("执行异常，请查看日志！！！");
    }
%>
<%!
    //将数据插入表单建模
    public static int insertModelData(int modeid, int userid, Map map){
        int dataid=0;
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        //查询该模块表名
        String sql = "select b.tablename,a.formid from modeinfo a left join workflow_bill b on a.formid=b.id where a.id=?";
        rs.executeQuery(sql,modeid);
        rs.next();
        String tablename= Util.null2String(rs.getString("tablename"));
        String uuid = UUID.randomUUID().toString();
        String insSql = "insert into "+tablename
                +"(uuid,modedatacreater,modedatacreatedate,modedatacreatetime,formmodeid)values(?,?,?,?,?)";
        Object[] params = {uuid, userid, TimeUtil.getCurrentDateString(), TimeUtil.getOnlyCurrentTimeString(), modeid};
        if(rs.executeUpdate(insSql,params)){
            rs1.executeQuery("select id from "+tablename+" where uuid=?",uuid);
            rs1.next();
            dataid= Util.getIntValue(rs1.getString("id"));
            if(dataid>0){
                //遍历数据 进行update
                String updatesql="update "+tablename+" set ";
                Set<String> keySet = map.keySet();
                for(String key : keySet){
                    updatesql+=key+"='"+map.get(key).toString()+"',";
                }
                if(updatesql.endsWith(",")){
                    updatesql=updatesql.substring(0, updatesql.length()-1);
                    updatesql+=" where id="+dataid;
                    rs.executeUpdate(updatesql);
                }
                //进行权限重构
                getNewModeRight(userid, modeid, dataid);
            }
        }
        return dataid;
    }
    //建模权限重构
    public static void getNewModeRight(int userid, int formmodeid, int id) {
        ModeRightInfo modeRightInfo = new ModeRightInfo();
        modeRightInfo.setNewRight( true );
        modeRightInfo.editModeDataShare( userid, formmodeid, id  );
    }
%>